package local.blueheart.data.jxmobilemigrate.domino;

import local.blueheart.data.jxmobilemigrate.util.NotesUtil;
import lotus.domino.Database;
import lotus.domino.NotesException;
import lotus.domino.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PooledDominoSession {

    private static final Logger LOGGER = LoggerFactory.getLogger(PooledDominoSession.class);

    private Session session;

    private boolean busy = false;

    public PooledDominoSession(Session session) {
        this.session = session;
    }

    public Session getSession() {
        return session;
    }

    public void setSession(Session session) {
        this.session = session;
    }

    public boolean isBusy() {
        return busy;
    }

    public void setBusy(boolean busy) {
        this.busy = busy;
    }

    /**
     * 获得Database对象
     * @param server 服务器域名或IP地址
     * @param dbPath 对应的数据库路径
     * @return
     */
    public DominoDb getDominoDb(String server,String dbPath){
        DominoDb dominoDb = null;
        Database db = null;
        try {
            db = session.getDatabase(server, dbPath);
            dominoDb = new DominoDb(db);
        } catch (NotesException e) {
            LOGGER.error("create DominoDb failure",e);
        }
        return dominoDb;
    }

    /**
     * recycle实现的session
     * @return
     */
    public boolean recycle(){
       return NotesUtil.recycle(session);
    }
}
